package net.oschina.app.cwq;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import net.oschina.app.Myapp;
import net.oschina.app.R;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.hjpbean.BlogBean;
import net.oschina.app.hjpbean.ExploreEventBean;
import net.oschina.app.util.BaseRecyclerAdapter;
import net.oschina.app.util.RecyclerViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Admin on 2017/7/16.
 */

public class JQFragment extends BaseFragment {

    private List<String> list;

    @BindView(R.id.rcv_news_zixun)
    RecyclerView rcvNewsZixun;
    @BindView(R.id.swipe_refresh_widget)
    SwipeRefreshLayout swipeRefreshWidget;
    Unbinder unbinder;
    private List<ExploreEventBean.EventBean> newsLists;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View jqfangment = inflater.inflate(R.layout.jqfragment, container, false);

        unbinder = ButterKnife.bind(this, jqfangment);
        return jqfangment;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

//        getshuju();

        initView();

//        String s=news.getUrl().toString();

        Log.d("baima", 123 + "");

    }

    public void getshuju() {

        Call<ExploreEventBean> info = Myapp.shopService.getActivity(1, 0, 20);

        info.enqueue(new Callback<ExploreEventBean>() {
            @Override
            public void onResponse(Call<ExploreEventBean> call, Response<ExploreEventBean> response) {

                newsLists = response.body().getEvents();

//                Log.d("baima", newsLists.get(15).getUrl().toString());a

                initView();

            }

            @Override
            public void onFailure(Call<ExploreEventBean> call, Throwable t) {

                t.printStackTrace();

            }
        });

    }

    private void initView() {

        list=new ArrayList<>();

        for (int i=0;i<20;i++){

            list.add(i+"");

        }

        rcvNewsZixun.setLayoutManager(new LinearLayoutManager(getContext()));


//        LinearLayoutManager manager = new LinearLayoutManager(getContext());
//        zongheZixunRcv.setLayoutManager(manager);

        RecyclerView.Adapter adapter = new BaseRecyclerAdapter<String>(getContext(), list) {
            @Override
            public int getItemLayoutId(int viewType) {

                return R.layout.jqfragment_item;

            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position, String item) {

                Log.d("baima", "到此一游王尼玛");
                holder.getImageView(R.id.jingqi_item_iv).setImageResource(R.drawable.luxun);
                holder.getTextView(R.id.jingqi_item_title).setText("假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!假标题!");
                holder.getTextView(R.id.jingqi_item_time).setText("假时间!假时间!");
                holder.getTextView(R.id.jingqi_item_dizhi).setText("五指山!五指山!五指山!五指山!五指山!五指山!五指山!");

            }


        };

        rcvNewsZixun.setAdapter(adapter);

        ((BaseRecyclerAdapter) adapter).setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int pos) {

                Toast.makeText(getContext(), "很懒,不跳了!", Toast.LENGTH_SHORT).show();
//                Intent intent=new Intent(getActivity(),ZiXunActivity.class);
//                intent.putExtra("id",newsLists.get(pos).getId());
//                startActivity(intent);

            }
        });


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
